<html>
<head><meta charset="utf-8"><title>mem::forget lack of guarantees · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html">mem::forget lack of guarantees</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="169857581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/169857581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#169857581">(Jul 08 2019 at 10:39)</a>:</h4>
<p>Someone pointed out to me on my recent blog post that mem::forget explicitly does not guarantee that pointers to the forgotten memory remain valid</p>



<a name="169857824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/169857824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#169857824">(Jul 08 2019 at 10:44)</a>:</h4>
<p>Could miri check this? (<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=8dea89516c17edbe73ae7eb1ce3d2165" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=8dea89516c17edbe73ae7eb1ce3d2165">AFACIT</a> it currently does not; see lines 15-17 of linked playpen.) And if it could, <em>should</em> it?</p>



<a name="170461455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170461455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170461455">(Jul 09 2019 at 15:03)</a>:</h4>
<p><a href="https://github.com/rust-lang/miri/issues/753" target="_blank" title="https://github.com/rust-lang/miri/issues/753">https://github.com/rust-lang/miri/issues/753</a></p>



<a name="170461530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170461530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170461530">(Jul 09 2019 at 15:04)</a>:</h4>
<p>I think it should be enough to make moves invalidate (set to undef) the bytes that are moved out of</p>



<a name="170461591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170461591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170461591">(Jul 09 2019 at 15:04)</a>:</h4>
<p>But that may end up becoming rather slow (especially since that's what's happening in many cases already via StorageDead)</p>



<a name="170461663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170461663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170461663">(Jul 09 2019 at 15:05)</a>:</h4>
<p>For moves via ptr::read this may not be an option, not sure.</p>



<a name="170645097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170645097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170645097">(Jul 11 2019 at 15:40)</a>:</h4>
<p>I think the game is still open whether <code>mem::forget</code> kills pointers</p>



<a name="170645114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170645114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170645114">(Jul 11 2019 at 15:40)</a>:</h4>
<p>seems strange to me honestly, it does explicilty <em>not</em> deallocate</p>



<a name="170645152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170645152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170645152">(Jul 11 2019 at 15:41)</a>:</h4>
<blockquote>
<p>I think it should be enough to make moves invalidate (set to undef) the bytes that are moved out of</p>
</blockquote>
<p>that's not enough, then you can still write to that memory</p>



<a name="170645175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170645175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170645175">(Jul 11 2019 at 15:41)</a>:</h4>
<p>I have not seen an operational model that lets us actually formalize this. and I dont believe in axiomatic semantics. ;)</p>



<a name="170716531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170716531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170716531">(Jul 12 2019 at 12:12)</a>:</h4>
<p>oh</p>



<a name="170716541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170716541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170716541">(Jul 12 2019 at 12:13)</a>:</h4>
<p>my mental model of moves is just undefing the memory that you move out of</p>



<a name="170779630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170779630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170779630">(Jul 13 2019 at 07:45)</a>:</h4>
<p>yes we have talked about that before. I just am still waiting to see a case where that actually enables any optimization.^^</p>



<a name="170779634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/mem%3A%3Aforget%20lack%20of%20guarantees/near/170779634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/mem.3A.3Aforget.20lack.20of.20guarantees.html#170779634">(Jul 13 2019 at 07:45)</a>:</h4>
<p>I thought it was useful. But I am not so sure any more.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>